home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / gnu / progutil / stdwin.zoo / vt / vtfunc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-10-17  |  4.1 KB  |  265 lines

  1. /* Functions implementing ANSI operations */
  2. /* $Header: vtfunc.c,v 1.5 88/06/03 14:44:17 guido Exp $ */
  3.  
  4. #include "vtimpl.h"
  5.  
  6. /* Linefeed */
  7.  
  8. void
  9. vtlinefeed(vt, n)
  10.     VT *vt;
  11.     int n;
  12. {
  13.     while (--n >= 0) {
  14.         if (vt->cur_row == vt->scr_bot - 1) {
  15.             int scr_top= vt->scr_top;
  16.             if (scr_top == vt->topterm)
  17.                 scr_top= 0;
  18.             vtscrollup(vt, scr_top, vt->scr_bot, 1);
  19.         }
  20.         else
  21.             vtsetcursor(vt, vt->cur_row + 1, vt->cur_col);
  22.     }
  23. }
  24.  
  25. /* Reverse linefeed */
  26.  
  27. void
  28. vtrevlinefeed(vt, n)
  29.     VT *vt;
  30.     int n;
  31. {
  32.     while (--n >= 0) {
  33.         if (vt->cur_row == vt->scr_top)
  34.             vtscrolldown(vt, vt->scr_top, vt->scr_bot, 1);
  35.         else
  36.             vtsetcursor(vt, vt->cur_row - 1, vt->cur_col);
  37.     }
  38. }
  39.  
  40. /* Reset underline, inverse video attributes */
  41.  
  42. void
  43. vtresetattr(vt)
  44.     VT *vt;
  45. {
  46.     vtsetflags(vt, 0);
  47. }
  48.  
  49. /* Set attribute flag (without clearing the others) */
  50.  
  51. void
  52. vtsetattr(vt, bit)
  53.     VT *vt;
  54.     int bit;
  55. {
  56.     vtsetflags(vt, vt->gflags | (1 << bit));
  57. }
  58.  
  59. /* Save cursor position */
  60.  
  61. void
  62. vtsavecursor(vt)
  63.     VT *vt;
  64. {
  65.     vt->save_row= vt->cur_row;
  66.     vt->save_col= vt->cur_col;
  67. }
  68.  
  69. /* Restore cursor position */
  70.  
  71. void
  72. vtrestorecursor(vt)
  73.     VT *vt;
  74. {
  75.     vtsetcursor(vt, vt->save_row, vt->save_col);
  76. }
  77.  
  78. /* Process an arrow key (possibly repeated) */
  79.  
  80. void
  81. vtarrow(vt, code, repeat)
  82.     VT *vt;
  83.     int code;
  84.     int repeat;
  85. {
  86.     int row= vt->cur_row;
  87.     int col= vt->cur_col;
  88.     int minrow= 0, maxrow= vt->rows;
  89.     
  90.     CLIPMAX(col, vt->cols-1);
  91.     switch (code) {
  92.     case WC_LEFT:
  93.         col -= repeat;
  94.         break;
  95.     case WC_RIGHT:
  96.         col += repeat;
  97.         break;
  98.     case WC_UP:
  99.         row -= repeat;
  100.         break;
  101.     case WC_DOWN:
  102.         row += repeat;
  103.         break;
  104.     }
  105.     CLIPMAX(col, vt->cols-1);
  106.     CLIPMIN(col, 0);
  107.     if (vt->cur_row >= vt->scr_top)
  108.         minrow= vt->scr_top;
  109.     if (vt->cur_row < vt->scr_bot)
  110.         maxrow= vt->scr_bot;
  111.     CLIPMIN(row, minrow);
  112.     CLIPMAX(row, maxrow-1);
  113.     vtsetcursor(vt, row, col);
  114. }
  115.  
  116. /* Clear to end of line */
  117.  
  118. void
  119. vteolclear(vt, row, col)
  120.     VT *vt;
  121.     int row, col;
  122. {
  123.     if (row < vt->rows) {
  124.         if (vt->llen[row] > col) {
  125.             vtchange(vt, row, col, row + 1, vt->llen[row]);
  126.             vt->llen[row]= col;
  127.         }
  128.     }    
  129. }
  130.  
  131. /* Clear to end of screen */
  132.  
  133. void
  134. vteosclear(vt, row, col)
  135.     VT *vt;
  136.     int row, col;
  137. {
  138.     vteolclear(vt, row, col);
  139.     vtchange(vt, row + 1, 0, vt->rows, vt->cols);
  140.     for (row= row + 1; row < vt->rows; ++row)
  141.         vt->llen[row]= 0;
  142. }
  143.  
  144. /* Delete n lines */
  145.  
  146. void
  147. vtdellines(vt, n)
  148.     VT *vt;
  149.     int n;
  150. {
  151.     vtscrollup(vt, vt->cur_row, vt->scr_bot, n);
  152. }
  153.  
  154. /* Insert n lines */
  155.  
  156. void
  157. vtinslines(vt, n)
  158.     VT *vt;
  159.     int n;
  160. {
  161.     vtscrolldown(vt, vt->cur_row, vt->scr_bot, n);
  162. }
  163.  
  164. /* Scroll a range of lines n positions up */
  165.  
  166. void
  167. vtscrollup(vt, r1, r2, n)
  168.     VT *vt;
  169.     int r1, r2;
  170.     int n;
  171. {
  172.     if (n > 0 && r1 < r2) {
  173.         int i;
  174.         vtcirculate(vt, r1, r2, r2 - r1 - n);
  175.         for (i= r2 - n; i < r2; ++i)
  176.             vt->llen[i]= 0;
  177.         vtscroll(vt, r1, 0, r2, vt->cols, -n, 0);
  178.     }
  179. }
  180.  
  181.  
  182. /* Scroll a range of lines n positions down */
  183.  
  184. void
  185. vtscrolldown(vt, r1, r2, n)
  186.     VT *vt;
  187.     int r1, r2;
  188.     int n;
  189. {
  190.     if (n > 0 && r1 < r2) {
  191.         int i;
  192.         vtcirculate(vt, r1, r2, n);
  193.         for (i= r1 + n; --i >= r1; )
  194.             vt->llen[i]= 0;
  195.         vtscroll(vt, r1, 0, r2, vt->cols, n, 0);
  196.     }
  197. }
  198.  
  199. /* Insert n characters */
  200.  
  201. void
  202. vtinschars(vt, n)
  203.     VT *vt;
  204.     int n;
  205. {
  206.     int row;
  207.     
  208.     if (n > 0 && (row= vt->cur_row) < vt->rows) {
  209.         int col= vt->cur_col;
  210.         int len= vt->llen[row];
  211.         if (len > col) {
  212.             if (col+n >= vt->cols) {
  213.                 vtchange(vt, row, col, row+1, len);
  214.                 vt->llen[row]= col;
  215.             }
  216.             else {
  217.                 register int i;
  218.                 char *data= vt->data[row];
  219.                 unsigned char *flags= vt->flags[row];
  220.                 len += n;
  221.                 if (len > vt->cols)
  222.                     len= vt->cols;
  223.                 for (i= len-n; --i >= col; )
  224.                     data[i+n]= data[i];
  225.                 vtscroll(vt, row, col, row+1, len, 0, n);
  226.                 vt->llen[row]= len;
  227.                 /* Clear the inserted stretch */
  228.                 for (i= col+n; --i >= col; ) {
  229.                     data[i]= ' ';
  230.                     flags[i]= 0;
  231.                 }
  232.             }
  233.         }
  234.     }
  235. }
  236.  
  237. /* Delete n characters */
  238.  
  239. void
  240. vtdelchars(vt, n)
  241.     VT *vt;
  242.     int n;
  243. {
  244.     int row;
  245.     
  246.     if (n > 0 && (row= vt->cur_row) < vt->rows) {
  247.         int col= vt->cur_col;
  248.         int len= vt->llen[row];
  249.         if (len > col) {
  250.             if (len <= col+n) {
  251.                 vtchange(vt, row, col, row+1, len);
  252.                 vt->llen[row]= col;
  253.             }
  254.             else {
  255.                 register int i;
  256.                 char *data= vt->data[row];
  257.                 for (i= col+n; i < len; ++i)
  258.                     data[i-n]= data[i];
  259.                 vtscroll(vt, row, col, row+1, len, 0, -n);
  260.                 vt->llen[row] -= n;
  261.             }
  262.         }
  263.     }
  264. }
  265.